﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class APP_Controls_Draw_Tab : System.Web.UI.UserControl
{
    protected List<Model.LotteryQs> LotteryQs = null;
    protected Model.LotteryQs lotteryqs = null;
    protected Model.LotteryQs dltqs = null;
    protected Model.LotteryQs sdqs = null;
    protected int secondsDiff;
    protected int dltseconds;
    protected int dseconds;
    protected DateTime endtime = new DateTime();
    protected void Page_Load(object sender, EventArgs e)
    { 
        int totalCount7 = 0;
        LotteryQs = BLL.LotteryQs.GetPageList_Where(0, 7, 0, out totalCount7);

        lotteryqs = BLL.LotteryQs.GetModel(1);
        DateTime DateTime2 = this.selectNextDate(lotteryqs.openWinWeek);
        secondsDiff = SecondsDiff(DateTime.Now, Convert.ToDateTime(DateTime2.Year + "-" + DateTime2.Month + "-" + DateTime2.Day + " 19:57:00"));


        dltqs = BLL.LotteryQs.GetModel(2);
        DateTime DateTimedlt = this.selectNextDate(dltqs.openWinWeek);
        dltseconds = SecondsDiff(DateTime.Now, Convert.ToDateTime(DateTimedlt.Year + "-" + DateTimedlt.Month + "-" + DateTimedlt.Day + " 19:57:00"));

        sdqs = BLL.LotteryQs.GetModel(5);

        DateTime DateTime3d = this.selectNextDate(sdqs.openWinWeek);
        dseconds = SecondsDiff(DateTime.Now, Convert.ToDateTime(DateTime3d.Year + "-" + DateTime3d.Month + "-" + DateTime3d.Day + " 19:57:00"));

    }
    public string selectLotteryJackpot(int lotteryType, string qs)
    {
        Model.LotteryJackpot lottery = BLL.LotteryJackpot.GetModelBysql(lotteryType, qs);
        return lottery != null ? lottery.LotteryMoney.ToString("##") : "0";
    }
    public int SecondsDiff(DateTime DateTime1, DateTime DateTime2)
    {
        int thisDiff = 0;
        try
        {
            TimeSpan ts1 = new TimeSpan(DateTime1.Ticks);
            TimeSpan ts2 = new TimeSpan(DateTime2.Ticks);
            TimeSpan ts = ts1.Subtract(ts2).Duration();
            thisDiff = Convert.ToInt32(ts.TotalSeconds);
        }
        catch
        {

        }
        return thisDiff;
    }
    public DateTime selectNextDate(string weekinfo)
    {
        DateTime timer = new DateTime();
        //遍历当天是星期几
        int week = -1;
        string weekstr = DateTime.Now.DayOfWeek.ToString();
        if (weekstr.Equals("Monday")) { week = 1; }
        else if (weekstr.Equals("Tuesday")) { week = 2; }
        else if (weekstr.Equals("Wednesday")) { week = 3; }
        else if (weekstr.Equals("Thursday")) { week = 4; }
        else if (weekstr.Equals("Friday")) { week = 5; }
        else if (weekstr.Equals("Saturday")) { week = 6; }
        else if (weekstr.Equals("Sunday")) { week = 7; }
        string[] weekList = weekinfo.Split(',');
        for (int i = 0; i < weekList.Length; i++)
        {
            if (week <= int.Parse(weekList[i]))
            {
                endtime = DateTime.Now.AddDays(int.Parse(weekList[i]) - week);
                timer = DateTime.Now.AddDays(int.Parse(weekList[i]) - week);
                break;
            }
        }
        return timer;
    }
}